﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class AdminPages_RegisterDispatch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        TableCell MovieID = GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0];
        TableCell UserName = GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[3];
        TableCell StockID = GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[4];

        MembershipUser user = Membership.GetUser(Convert.ToString(UserName.Text));

        //Set Userfield for rented dvd on true
        DVDTableAdapters.CustomerTableAdapter ta1 = new DVDTableAdapters.CustomerTableAdapter();
        ta1.UpdateDVDDispatchAndReturn(true, (Guid)user.ProviderUserKey);

        //Set DvD availability false
        DVDTableAdapters.DVDStockTableAdapter ta2 = new DVDTableAdapters.DVDStockTableAdapter();
        ta2.UpdateMovieAvailability(false, Convert.ToInt32(StockID.Text));

        //Write DVD in User History
        DVDTableAdapters.UserhistoryMovieTableAdapter ta3 = new DVDTableAdapters.UserhistoryMovieTableAdapter();
        ta3.Insert(Convert.ToInt32(MovieID.Text), (Guid)user.ProviderUserKey, System.DateTime.Now,System.DateTime.Now.AddDays(7),false,false);

        //Set DVD History
        DVDTableAdapters.DVDHistoryTableAdapter ta4 = new DVDTableAdapters.DVDHistoryTableAdapter();
        ta4.Insert(System.DateTime.Now,System.DateTime.Now.AddDays(7),Convert.ToInt32(StockID.Text),Convert.ToInt32(MovieID.Text));

        //Write DVD Actualrented
        DVDTableAdapters.ActualRentTableAdapter ta6 = new DVDTableAdapters.ActualRentTableAdapter();
        ta6.Insert((Guid)user.ProviderUserKey, Convert.ToInt32(MovieID.Text), System.DateTime.Now, System.DateTime.Now.AddDays(7),Convert.ToInt32(StockID.Text));

        //Remove DVD From RentalList
        DVDTableAdapters.RentalListMoviesTableAdapter ta7 = new DVDTableAdapters.RentalListMoviesTableAdapter();
        ta7.DeleteMovieRentalList(Convert.ToInt32(MovieID.Text), (Guid)user.ProviderUserKey);

        
        user = null;
        Response.Redirect(Request.RawUrl);

       


    }
}